package com.apes.fn.server.productRequire;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.metadata.BusinessAttributeValue;
import com.apes.framework.plugin.soe.metadata.BusinessType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = RequireInfoConfigur.CONST_TABLE_NAME)
public class RequireInfoConfigur extends Model {
    public static final String CONST_TABLE_NAME = "stock_require_info_configur";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "要货物流参数配置", padding = 1)
    @Comment("编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "business_type_id", referencedColumnName = "id", nullable = false)
    @Comment("凭证类型")
    private BusinessType businessType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "business_attribute_value_id", referencedColumnName = "id", nullable = false)
    @Comment("凭证属性值")
    private BusinessAttributeValue businessAttributeValue;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "up_business_type_id", referencedColumnName = "id")
    @Comment("上游凭证类型")
    private BusinessType upBusinessType; // 当一个单多个来源需要多个消息的时候, 用这个确认使用哪个消息, 如普通采购订单和外采询价单产生的采购订单

    @Column(name = "message", nullable = false, length = 3000)
    @Comment("消息")
    private String message;

    @Column(name = "one_mark", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("只执行一次") // 不带明细
    private boolean oneMark = true;

//    @Column(name = "requireInfo_configur_id")
//    @Comment("上级")
//    private RequireInfoConfigur requireInfoConfigur;

    @Column(name = "parameter", nullable = false, length = 3000)
    @Comment("参数")
    private String parameter; // 以分号隔开

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("有效标记")
    private boolean valid = true;



}
